#ifndef _ASTRO_HOROSCOPECHARTPAGE_H
#define _ASTRO_HOROSCOPECHARTPAGE_H

#include <webkit/webkit.h>
#include "../Page.h"
#include "Horoscope.h"


#define CHART_CONTENT_RING					0
#define CHART_CONTENT_RULER				1
#define CHART_CONTENT_ELEMENTS			2
#define CHART_CONTENT_ZODIAC				3
#define CHART_CONTENT_PLANETS				4
#define CHART_CONTENT_HOUSES				5
#define CHART_CONTENT_ASC_MC_ARROW		6
#define CHART_CONTENT_ASPECTS				7

#define Z 12
#define P 17
#define P2 34
#define H 12
#define H2 24


class HoroscopeChartPage : public Page {
public:
	struct graph_content {
		int type;
		double angle;
		int p1,p2,p3,p4;
		int color[4];
	};

	struct graph_level {
		double size;
		int ncontent;
		graph_content *content;
	};

	struct graph_style {
		int x;
		int y;
		int width;
		int height;
		int bgcolor;
		int *element_colors;
		int *zodiac_colors;
		int *planet_colors;
		int *aspect_colors;
		int nlevels;
		graph_level *levels;
	};

private:
	struct {
		GtkWidget *webview;
		GtkWidget *graph_area;
		GdkRectangle graph,info;
	} gtk;

	int counter,planetHover,planetFocus,graphSize,tableWidth,xc,yc;
	double ascendant;
	bool focus;

	static void webview_hover_event_callback(WebKitWebView *webview,gchar *title,gchar *uri,gpointer data);
	static gboolean webview_navigation_decision_event_callback(WebKitWebView *webview,WebKitWebFrame *frame,WebKitNetworkRequest *request,
																	WebKitWebNavigationAction *action,WebKitWebPolicyDecision *decision,gpointer data);
//	static gboolean webview_navigation_event_callback(WebKitWebView *webview,WebKitWebFrame *frame,WebKitNetworkRequest *request,gpointer data);
	static gboolean graph_configure_event_callback(GtkWidget *widget,GdkEventConfigure *event,gpointer data);
	static gboolean graph_expose_event_callback(GtkWidget *widget,GdkEventExpose *event,gpointer data);

	void paintNatal();
	void paintSolarSystem();
	void paintSynastry();
	void paintComposite();

	void paintGraph(cairo_t *cr,graph_style &gs);
	void paintGraph(int fs,int *rings,int *style,int len,int offset=0);
	void paintHouses(int fs,int r0,int r1,int r2,int r3,Horoscope &h,int c1,int c2);
	void paintPlanets(int fs,int r1,int r2,int r3,Horoscope &h,GdkRectangle *pl,double *pa,int c);
	void paintAspects(int r,Horoscope &h1,Horoscope &h2,bool syn);

	void writeHoroscope(aString &str);
	void writeChartInfo(aString &str,Horoscope &h,int col=0);
	void writePlanetTable(aString &str);
	void writeHouseTable(aString &str);
	void writeFactors(aString &str);
	void writeAspectTable(aString &str);
	void writePatterns(aString &str);

	void positionPlanet(int n,GdkRectangle *r,double *an,double a,int fs,int r1,Horoscope &h,int l,int c);
	int intersectPlanet(int n,GdkRectangle &r,GdkRectangle *l,int len);
	void clearPlanetLocations(Horoscope &h,GdkRectangle *r,double *an=0);

	int findPoint(int x,int y);

public:
	static float planetSizes[11];
	static float planetDistances[11];

	static bool aspectShow[23];

	static const double circle,trine,step,half;

	Horoscope *horoscope;
	GdkRectangle zodiacLocations[ASTRO_PISCES+1],planetLocations1[18],planetLocations2[18];
	double planetAngles1[18],planetAngles2[18];

	HoroscopeChartPage(Horoscope *h);
	~HoroscopeChartPage();

	void paint();

	int mouseMove(int x,int y,GdkPoint *drag,int params);
	int mouseDown(int x,int y,int params);

	static const char *hms(double d);
};



#endif /* _ASTRO_HOROSCOPECHARTPAGE_H */


